<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<!-- 一个数字各个位相加,直至位数为一 -->
</body>
</html>
<script>
    var addDigits = function (num) {
        function foo(s) {
            let myNum = s.toString().split("").reduce((a, b) => parseInt(a) + parseInt(b));
            let n = myNum.toString().length;
            if (n > 1) {
                return foo(myNum)
            } else {
                return myNum;
            }
        }
        if (num.toString().length > 1) {
            return foo(num)
        } else {
            return num;
        }
    }
    console.log(addDigits(1915));//7
</script>